package com.javasm.mb_store_api_final.giftsandgoods.goodsSupplier.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.javasm.common.R;
import com.javasm.mb_store_api_final.giftsandgoods.goods.entity.GgGoods;
import com.javasm.mb_store_api_final.giftsandgoods.goods.service.GgGoodsService;
import com.javasm.mb_store_api_final.giftsandgoods.goodsSupplier.entity.GgSupplier;
import com.javasm.mb_store_api_final.giftsandgoods.goodsSupplier.service.GgSupplierService;
import com.javasm.mb_store_api_final.giftsandgoods.goodsSupplier.vo.GgGoodsListVo;
import com.javasm.mb_store_api_final.giftsandgoods.goodsSupplier.vo.GgSupplierVo;
import com.javasm.mb_store_api_final.giftsandgoods.goodsType.entity.GgGoodsType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author lh
 * @version 0.1
 * @className GoodsSupplierController
 * @date 2024/8/4 22:43
 * @description
 * @since jdk11
 */
@RestController
@RequestMapping("/goodsSupplier")
public class GoodsSupplierController {
    @Resource
    GgSupplierService goodsSupplierService;
    @Resource
    GgGoodsService ggGoodsService;
    //查询供应商列表
    @RequestMapping("/list")
    public R list(@RequestBody GgSupplierVo supplierVo) {
        IPage<GgSupplier> page = goodsSupplierService.listBySupplierNameAndContacts(supplierVo);
        return R.ok(page);
    }
    //添加供应商
    @RequestMapping("/addSupplier")
    public R addSupplier(@RequestBody GgSupplier supplier) {
        boolean b = goodsSupplierService.save(supplier);
        return R.ok(b);
    }
    //删除供应商
    @RequestMapping("/deleteSupplier")
    public R deleteSupplier(@RequestBody GgSupplier supplier) {
        boolean b = goodsSupplierService.removeById(supplier.getId());
        return R.ok(b);
    }
    //修改供应商
    @RequestMapping("/updateSupplier")
    public R updateSupplier(@RequestBody GgSupplier supplier) {
        boolean b = goodsSupplierService.updateById(supplier);
        return R.ok(b);
    }
    //根据id查询供应商
    @RequestMapping("/getById")
    public R getById(@RequestBody GgSupplier supplier) {
        GgSupplier ggSupplier = goodsSupplierService.getById(supplier.getId());
        return R.ok(ggSupplier);
    }
    //根据sid查gid,再根据gid查商品
    @RequestMapping("/getGoodsBySid")
    public R getGoodsBySid(@RequestBody GgSupplier supplier) {
        List<GgGoods> goodsList = goodsSupplierService.getGgGoodsBySid(supplier.getId());
        return R.ok(goodsList);
    }
    //向供应商添加商品
    @RequestMapping("/addGoods")
    public R addGoods(@RequestBody GgGoodsListVo goodsListVo) {
        goodsSupplierService.addGoodsByIdAndListGid(goodsListVo);
        return R.ok();
    }

}
